import http from '@/utils/request';

interface Device {
    id: string;
    name: string;
    address: string;
    latitude: number;
    longitude: number;
    distance: number;
    status: number;
    contactPhone: string;
}

// 地理编码（地址转坐标）
export function geocode(address: string, city?: string) {
    return http.get('/map/map/geocode', {
        address,
        city,
        key: '8a1e4e4aca95d111e90be19748a0aa17'
    });
}

// 逆地理编码（坐标转地址）
export function regeocode(longitude: number, latitude: number) {
    return http.get('/map/map/regeocode', {
        longitude,
        latitude,
        key: '8a1e4e4aca95d111e90be19748a0aa17'
    });
}

// 计算两点之间的距离
export function calculateDistance(fromLongitude: number, fromLatitude: number, toLongitude: number, toLatitude: number) {
    return http.get('/map/map/distance', {
        fromLongitude,
        fromLatitude,
        toLongitude,
        toLatitude,
        key: '8a1e4e4aca95d111e90be19748a0aa17'
    });
}

// 获取行政区划信息
export function getDistricts(keywords: string, subdistrict: number = 1) {
    return http.get('/map/districts', {
        keywords,
        subdistrict,
        key: '8a1e4e4aca95d111e90be19748a0aa17'
    });
}

// 查询指定范围内的设备
export function searchAround(longitude: number, latitude: number, keywords: string, radius: number = 5) {
    return http.get('/vending/device/es/nearby', {
        longitude: longitude,
        latitude: latitude,
        distance: radius,
        keywords: keywords
    });
}

// 分页查询指定范围内的设备
export function pageNearbyDevices(longitude: number, latitude: number, distance: number = 5, pageNum: number = 1, pageSize: number = 10) {
    return http.get('/vending/device/es/nearby/page', {
        longitude: longitude,
        latitude: latitude,
        distance: distance,
        pageNum: pageNum,
        pageSize: pageSize
    });
}

// 查询圆形范围内的设备
export function listDevicesInCircle(longitude: number, latitude: number, radius: number = 5) {
    return http.get('/vending/device/es/circle', {
        longitude: longitude,
        latitude: latitude,
        radius: radius
    });
}

// 分页查询圆形范围内的设备
export function pageDevicesInCircle(longitude: number, latitude: number, radius: number = 5, pageNum: number = 1, pageSize: number = 10) {
    return http.get('/vending/device/es/circle/page', {
        longitude: longitude,
        latitude: latitude,
        radius: radius,
        pageNum: pageNum,
        pageSize: pageSize
    });
}

// 步行路线规划
export function planWalkingRoute(fromLongitude: number, fromLatitude: number, toLongitude: number, toLatitude: number) {
    return http.get('/map/map/walking', {
        fromLongitude,
        fromLatitude,
        toLongitude,
        toLatitude
    });
}

// 获取IP地址
export function getIp() {
    return http.get('/map/map/getIP');
}

// 根据IP获取位置信息
export function getLocationByIp(ip?: string) {
    return http.get('/map/map/ip', {
        ip
    });
} 